import { getPlanRecord } from '../../api/long-insure'
Page({
    data: {
        record: []
    },
    static: {
        id: null,
        pageNum: 1,
        hasNext: 1,
        search: ''
    },
    onLoad(options){
        this.static.id = options.id
        this.getPlanRecord()
    },
    onSearch(event){
        this.static.search = event.detail.value
        this.getPlanRecord(1)
    },
    onReachBottom(){
        this.getPlanRecord()
    },
    // 获取保单加减保记录（分页）
    async getPlanRecord(clear){
        if(clear){
            this.static.pageNum = 1
            this.static.hasNext = true
            this.data.record = []
        }
        if(!this.static.hasNext){
            return
        }
        const result = await getPlanRecord({
            companyPlanId: this.static.id,
            pageNum: this.static.pageNum,
            pageSize: 20,
            // preciseSearchUserInfo: this.static.search,
            searchText: this.static.search
        })
        this.static.hasNext = result.hasNextPage
        this.static.pageNum += 1
        this.data.record.push(...result.list)
        this.setData({
            record:  this.data.record
        })
    },
    async onRevoke(){ 
        console.log('父回调') 
        await this.getPlanRecord(1)
    } 
})